package com.tequila.core.service.impl;

import com.google.common.collect.Lists;
import com.tequila.core.dao.CardCouponWishDao;
import com.tequila.core.service.CardCouponWishService;
import com.tequila.domain.dto.CardCouponWishDto;
import com.tequila.domain.entity.CardCouponWish;
import com.tequila.domain.query.CardCouponWishQuery;
import fe.core.Assert;
import fe.core.BeanHelper;
import fe.core.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CardCouponWishServiceImpl implements CardCouponWishService {
    public static final Logger logger = LoggerFactory.getLogger(CardCouponWishServiceImpl.class);

    @Resource
    private CardCouponWishDao cardCouponWishDao;

    @Override
    public Pagination<CardCouponWishDto> queryPageListByParam(CardCouponWishQuery query) {
        Assert.assertNotNull(query);
        int total = cardCouponWishDao.queryPageCountByParam(query);

        List<CardCouponWishDto> list = Lists.newArrayList();
        if (total > 0) {
            list = cardCouponWishDao.queryPageListByParam(query);
        }
        return new Pagination<>(query, list, total);
    }

    @Override
    public CardCouponWishDto queryById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        CardCouponWish cardCouponWish = cardCouponWishDao.queryById(id);
        CardCouponWishDto cardCouponWishDto = new CardCouponWishDto();
        BeanHelper.copyProperties(cardCouponWishDto,cardCouponWish);
        return cardCouponWishDto;
    }

    @Override
    public List<CardCouponWishDto> queryByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponWishDao.queryByIdList(idList);
    }

    @Override
    public List<CardCouponWishDto> queryListByParam(CardCouponWishQuery query) {
        Assert.assertNotNull(query,"query不能为空!");
        return cardCouponWishDao.queryListByParam(query);
    }


    @Override
    public Long insert(CardCouponWish entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponWishDao.insert(entity);
        return entity.getId();
    }

    @Override
    public Long save(CardCouponWish entity) {
        Assert.assertNotNull(entity,"entity不能为空!");
        cardCouponWishDao.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public int updateById(CardCouponWish param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponWishDao.updateById(param);
    }

    @Override
    public int updateSelectiveById(CardCouponWish param) {
        Assert.assertNotNull(param,"param不能为空!");
        Assert.assertNotNull(param.getId(),"id不能为空!");
        return cardCouponWishDao.updateSelectiveById(param);
    }

    @Override
    public int deleteById(Long id) {
        Assert.assertNotNull(id,"id不能为空!");
        return cardCouponWishDao.deleteById(id);
    }

    @Override
    public int deleteByIdList(List<Long> idList) {
        Assert.assertNotNull(idList,"idList不能为空!");
        return cardCouponWishDao.deleteByIdList(idList);
    }
}
